package com.jxc.action.qxgl;



import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;


import com.jxc.action.BaseAction;
import com.jxc.model.vo.Online;
import com.jxc.model.vo.SessionInfo;
import com.jxc.model.vo.VUser;
import com.jxc.service.MemberServiceI;
import com.jxc.service.OnlineServiceI;
import com.jxc.service.RepertoryServiceI;
import com.jxc.service.UserServiceI;
import com.jxc.util.ResourceUtil;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 在线列表ACTION
 * 
 * @author 孙宇
 * 
 */
@Namespace("/qxgl")
@Action(value = "onlineAction")
public class OnlineAction extends BaseAction implements ModelDriven<Online> {

	private Online online = new Online();

	@Autowired
	private UserServiceI userService;
	@Autowired
	private RepertoryServiceI reperService;
	public Online getModel() {
		return online;
	}

	private OnlineServiceI demoOnlineService;

	public OnlineServiceI getDemoOnlineService() {
		return demoOnlineService;
	}

	@Autowired
	public void setDemoOnlineService(OnlineServiceI demoOnlineService) {
		this.demoOnlineService = demoOnlineService;
	}

	public void findDoNotNeedSession_onlineDatagrid() {
		try {
			SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute(ResourceUtil.getSessionInfoName());
			if(sessionInfo.getRepertoryIds()!=null&&!sessionInfo.getRepertoryIds().trim().equals("null")){
				Long id = reperService.getUidByReper(Long.parseLong(sessionInfo.getRepertoryIds()));
				online.setUid(id);
			}else{
				online.setUid(sessionInfo.getUserId());
			}
			online.setUsertype(sessionInfo.getType());
			
			super.writeJson(demoOnlineService.datagrid(online));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
